Skip to content

fix(plausible): honor scriptInput.src in bundle.resolve for self-hosted#775

Merged
harlan-zw merged 2 commits into
mainfrom
fix/plausible-self-hosted-bundle
May 14, 2026
Merged

fix(plausible): honor scriptInput.src in bundle.resolve for self-hosted#775
harlan-zw merged 2 commits into
mainfrom
fix/plausible-self-hosted-bundle

Conversation

@harlan-zw
Copy link
Copy Markdown
Collaborator

@harlan-zw harlan-zw commented May 14, 2026

🔗 Linked issue

Resolves #768

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Self-hosted Plausible was broken in v1.0.6. The bundle transformer (packages/script/src/plugins/transform.ts) calls bundle.resolve() with the merged registry config to determine which URL to download at build time. Plausible's resolver only looked at scriptId/extension, always returning plausible.io, so:

  • Self-hosted users hit 404 / fetch failed against https://plausible.io/js/pa-<id>.js during bundling.
  • With proxy: false, the build error went away but the rewritten script still pointed at plausible.io, so the runtime scriptInput.src override never took effect.

Bundle resolver now honors options.scriptInput?.src first, so self-hosted Plausible bundles (and runs) against the user-configured origin.

✅ Verification

  • pnpm vitest run --project unit test/unit/plausible-bundle-resolve.test.ts (new regression test)
  • pnpm vitest run --project unit — 675 passed, 2 todo
  • Manual: reproduction from issue (stackblitz nuxt-starter-sapvn3tf) builds without hitting plausible.io

The build-time bundle transformer calls `bundle.resolve()` with the merged
registry config to determine which URL to download. For Plausible, the
resolver only inspected `scriptId`/`extension` and always returned
`plausible.io`, so self-hosted users hit fetch failures (e.g.
`https://plausible.io/js/pa-<id>.js` → 404) at build time and runtime
overrides were never reached.

Honor `options.scriptInput?.src` first so self-hosted Plausible bundles
from the user-configured origin.

Fixes #768
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
scripts-playground Ready Ready Preview, Comment May 14, 2026 5:06am

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@775

commit: 12ba388

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 39d3251e-b733-4fdf-b1ba-bec9e24483e5

📥 Commits

Reviewing files that changed from the base of the PR and between f5cc40d and 12ba388.

📒 Files selected for processing (1)
  • packages/script/src/registry.ts

📝 Walkthrough

Walkthrough

This PR adds self-hosted Plausible support to the bundle resolver. The implementation checks if options.scriptInput.src is provided as a non-empty string and returns it directly; otherwise it falls back to the default Plausible CDN URLs. A new test suite verifies default resolution, legacy URL formats, and the self-hosted override behavior with four distinct test cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: honoring scriptInput.src in bundle.resolve for self-hosted Plausible, which directly addresses the linked issue #768.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the bug, root cause, the fix, and verification steps performed.
Linked Issues check ✅ Passed The changes successfully address the requirements in issue #768: the bundle resolver now honors options.scriptInput?.src for self-hosted Plausible, both at build time and runtime, with regression test coverage included.
Out of Scope Changes check ✅ Passed All changes are directly within scope: registry modification for plausibleAnalytics bundle.resolve behavior and new unit test for regression coverage, with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/plausible-self-hosted-bundle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/script/src/registry.ts`:
- Around line 307-308: The current check allows whitespace-only scriptInput.src
because it only tests userSrc.length; update the logic around userSrc (derived
from scriptInput.src) to use a trimmed check and return the trimmed value:
require typeof userSrc === 'string' && userSrc.trim().length > 0 before
returning, and return userSrc.trim() so whitespace-only values are treated as
unset and genuine URLs are normalized. This change should be made in the same
block that currently contains the if (typeof userSrc === 'string' &&
userSrc.length > 0) return userSrc check in registry.ts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 361c9806-cb9b-45d9-b51c-a30d743cb180

📥 Commits

Reviewing files that changed from the base of the PR and between 6129314 and f5cc40d.

📒 Files selected for processing (2)
  • packages/script/src/registry.ts
  • test/unit/plausible-bundle-resolve.test.ts

Comment thread packages/script/src/registry.ts Outdated
@harlan-zw harlan-zw merged commit fb50b0a into main May 14, 2026
25 of 27 checks passed
@harlan-zw harlan-zw deleted the fix/plausible-self-hosted-bundle branch May 14, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

self-hosted plausible cannot be used

1 participant